<%@ page language="java" contentType="text/html; charset=UTF-8"  isErrorPage="true"
    pageEncoding="UTF-8"%>
<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="useredit">
        <input type="hidden" name="id" value="">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
              <label class="layui-form-label required">用户类型</label>
              <div class="layui-input-block">
                  <select name="type" lay-filter="role">
                      <option value="">请选择用户类型</option>
                      <option value="管理员">管理员</option>
                      <option value="家长">家长</option>
                      <option value="学生">学生</option>
                  </select>
              </div>
         </div>
        
        <div class="layui-form-item layui-form-text">
           <label class="layui-form-label">备注</label>
           <div class="layui-input-block">
               <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
           </div>
        </div> 

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script src="/PC_educationms/js/jquery-3.3.1.js"></script>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("确定修改用户信息！", {
                title: '提交信息'
            }, function () {
                 console.log(data);
                 $.ajax({
                	 url:"/PC_educationms/user/updateUser",
                	 data:JSON.stringify(data.field),
                	 type:"POST",
                	 dataType:"json",
                     contentType:"application/json",
                	 success:function(data){
                		 console.log(data);
                   		 // data = JSON.parse(data);
                   		 if(data.msg == "ok") {
                   			// 关闭弹出层
                            layer.close(index);
                            layer.close(parentIndex);
                            $(".layui-laypage-btn")[0].click();
                   		 }else{
                             layer.alert('修改失败！请输入正确信息。'+(data.handle!=undefined?data.handle:""));
                      	}
                	 }
                 })
            });
            return false;
        });

    });
</script>